home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / system / xptools / xtsetup.exe / {app} / script / _TreeView / ftiens4.js next >
Encoding:
JavaScript  |  2004-07-11  |  11.4 KB  |  455 lines

  1.  
  2.  
  3. // Definition of class Folder 
  4. // ***************************************************************** 
  5.  
  6. function Folder(folderDescription, hreference) //constructor 
  7.   //constant data 
  8.   this.desc = folderDescription 
  9.   this.hreference = hreference 
  10.   this.id = -1   
  11.   this.navObj = 0  
  12.   this.iconImg = 0  
  13.   this.nodeImg = 0  
  14.   this.isLastNode = 0 
  15.  
  16.   //dynamic data 
  17.   this.isOpen = true 
  18.   this.iconSrc = "_TreeView/ftv2folderopen.gif"   
  19.   this.children = new Array 
  20.   this.nChildren = 0 
  21.  
  22.   //methods 
  23.   this.initialize = initializeFolder 
  24.   this.setState = setStateFolder 
  25.   this.addChild = addChild 
  26.   this.createIndex = createEntryIndex 
  27.   this.hide = hideFolder 
  28.   this.display = display 
  29.   this.renderOb = drawFolder 
  30.   this.totalHeight = totalHeight 
  31.   this.subEntries = folderSubEntries 
  32.   this.outputLink = outputFolderLink 
  33.  
  34. function setStateFolder(isOpen) 
  35.   var subEntries 
  36.   var totalHeight 
  37.   var fIt = 0 
  38.   var i=0 
  39.  
  40.   if (isOpen == this.isOpen) 
  41.     return 
  42.  
  43.   if (browserVersion == 2)  
  44.   { 
  45.     totalHeight = 0 
  46.     for (i=0; i < this.nChildren; i++) 
  47.       totalHeight = totalHeight + this.children[i].navObj.clip.height 
  48.       subEntries = this.subEntries() 
  49.     if (this.isOpen) 
  50.       totalHeight = 0 - totalHeight 
  51.     for (fIt = this.id + subEntries + 1; fIt < nEntries; fIt++) 
  52.       indexOfEntries[fIt].navObj.moveBy(0, totalHeight) 
  53.   }  
  54.   this.isOpen = isOpen 
  55.   propagateChangesInState(this) 
  56.  
  57. function propagateChangesInState(folder) 
  58. {   
  59.   var i=0 
  60.  
  61.   if (folder.isOpen) 
  62.   { 
  63.     if (folder.nodeImg) 
  64.       if (folder.isLastNode) 
  65.         folder.nodeImg.src = "_TreeView/ftv2mlastnode.gif" 
  66.       else 
  67.       folder.nodeImg.src = "_TreeView/ftv2mnode.gif" 
  68.     folder.iconImg.src = "_TreeView/ftv2folderopen.gif" 
  69.     for (i=0; i<folder.nChildren; i++) 
  70.       folder.children[i].display() 
  71.   } 
  72.   else 
  73.   { 
  74.     if (folder.nodeImg) 
  75.       if (folder.isLastNode) 
  76.         folder.nodeImg.src = "_TreeView/ftv2plastnode.gif" 
  77.       else 
  78.       folder.nodeImg.src = "_TreeView/ftv2pnode.gif" 
  79.     folder.iconImg.src = "_TreeView/ftv2folderclosed.gif" 
  80.     for (i=0; i<folder.nChildren; i++) 
  81.       folder.children[i].hide() 
  82.   }  
  83.  
  84. function hideFolder() 
  85.   if (browserVersion == 1) { 
  86.     if (this.navObj.style.display == "none") 
  87.       return 
  88.     this.navObj.style.display = "none" 
  89.   } else { 
  90.     if (this.navObj.visibility == "hiden") 
  91.       return 
  92.     this.navObj.visibility = "hiden" 
  93.   } 
  94.    
  95.   this.setState(0) 
  96.  
  97. function initializeFolder(level, lastNode, leftSide) 
  98. var j=0 
  99. var i=0 
  100. var numberOfFolders 
  101. var numberOfDocs 
  102. var nc 
  103.       
  104.   nc = this.nChildren 
  105.    
  106.   this.createIndex() 
  107.  
  108.   var auxEv = "" 
  109.  
  110.   if (browserVersion > 0) 
  111.     auxEv = "<a href='javascript:clickOnNode("+this.id+")'>" 
  112.   else 
  113.     auxEv = "<a>" 
  114.  
  115.   if (level>0) 
  116.     if (lastNode) //the last 'brother' in the children array 
  117.     { 
  118.       this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' src='_TreeView/ftv2mlastnode.gif' width=16 height=22 border=0></a>") 
  119.       leftSide = leftSide + "<img src='_TreeView/ftv2blank.gif' width=16 height=22>"  
  120.       this.isLastNode = 1 
  121.     } 
  122.     else 
  123.     { 
  124.       this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' src='_TreeView/ftv2mnode.gif' width=16 height=22 border=0></a>") 
  125.       leftSide = leftSide + "<img src='_TreeView/ftv2vertline.gif' width=16 height=22>" 
  126.       this.isLastNode = 0 
  127.     } 
  128.   else 
  129.     this.renderOb("") 
  130.    
  131.   if (nc > 0) 
  132.   { 
  133.     level = level + 1 
  134.     for (i=0 ; i < this.nChildren; i++)  
  135.     { 
  136.       if (i == this.nChildren-1) 
  137.         this.children[i].initialize(level, 1, leftSide) 
  138.       else 
  139.         this.children[i].initialize(level, 0, leftSide) 
  140.       } 
  141.   } 
  142.  
  143. function drawFolder(leftSide) 
  144.   if (browserVersion == 2) { 
  145.     if (!doc.yPos) 
  146.       doc.yPos=8 
  147.     doc.write("<layer id='folder" + this.id + "' top=" + doc.yPos + " visibility=hiden>") 
  148.   } 
  149.    
  150.   doc.write("<table ") 
  151.   if (browserVersion == 1) 
  152.     doc.write(" id='folder" + this.id + "' style='position:block;' ") 
  153.   doc.write(" border=0 cellspacing=0 cellpadding=0>") 
  154.   doc.write("<tr><td>") 
  155.   doc.write(leftSide) 
  156.   this.outputLink() 
  157.   doc.write("<a href='javascript:clickOnNode("+this.id+")'>"+"<img name='folderIcon" + this.id + "' ") 
  158.   doc.write("src='" + this.iconSrc+"' border=0></a>") 
  159.   doc.write("</td><td valign=middle nowrap>"+"<a href='javascript:clickOnNode("+this.id+")'>") 
  160.   if (USETEXTLINKS) 
  161.   { 
  162.     this.outputLink() 
  163.     doc.write(this.desc + "</a>") 
  164.   } 
  165.   else 
  166.     doc.write(this.desc) 
  167.   doc.write("</a></td>")  
  168.   doc.write("</table>") 
  169.    
  170.   if (browserVersion == 2) { 
  171.     doc.write("</layer>") 
  172.   } 
  173.  
  174.   if (browserVersion == 1) { 
  175.     this.navObj = doc.all["folder"+this.id] 
  176.     this.iconImg = doc.all["folderIcon"+this.id] 
  177.     this.nodeImg = doc.all["nodeIcon"+this.id] 
  178.   } else if (browserVersion == 2) { 
  179.     this.navObj = doc.layers["folder"+this.id] 
  180.     this.iconImg = this.navObj.document.images["folderIcon"+this.id] 
  181.     this.nodeImg = this.navObj.document.images["nodeIcon"+this.id] 
  182.     doc.yPos=doc.yPos+this.navObj.clip.height 
  183.   } 
  184.  
  185. function outputFolderLink() 
  186.   if (this.hreference) 
  187.   { 
  188.   //  doc.write("<a href='" + this.hreference + "' TARGET=\"basefrm\" ") 
  189.     doc.write("<a href='" + this.hreference + "' TARGET=\"main\" ") 
  190.     if (browserVersion > 0) 
  191.       doc.write("onClick='javascript:clickOnFolder("+this.id+")'") 
  192.     doc.write(">") 
  193.   } 
  194.   else 
  195.  
  196. {  doc.write("<a>") 
  197.   doc.write("<a href='javascript:clickOnFolder("+this.id+")'>")   
  198. }
  199.  
  200. function addChild(childNode) 
  201.   this.children[this.nChildren] = childNode 
  202.   this.nChildren++ 
  203.   return childNode 
  204.  
  205. function folderSubEntries() 
  206.   var i = 0 
  207.   var se = this.nChildren 
  208.  
  209.   for (i=0; i < this.nChildren; i++){ 
  210.     if (this.children[i].children) //is a folder 
  211.       se = se + this.children[i].subEntries() 
  212.   } 
  213.  
  214.   return se 
  215.  
  216.  
  217. // Definition of class Item (a document or link inside a Folder) 
  218. // ************************************************************* 
  219.  
  220. function Item(itemDescription, itemLink) // Constructor 
  221.   // constant data 
  222.   this.desc = itemDescription 
  223.   this.link = itemLink 
  224.   this.id = -1 //initialized in initalize() 
  225.   this.navObj = 0 //initialized in render() 
  226.   this.iconImg = 0 //initialized in render() 
  227.   this.iconSrc = "_TreeView/ftv2doc.gif" 
  228.  
  229.   // methods 
  230.   this.initialize = initializeItem 
  231.   this.createIndex = createEntryIndex 
  232.   this.hide = hideItem 
  233.   this.display = display 
  234.   this.renderOb = drawItem 
  235.   this.totalHeight = totalHeight 
  236.  
  237. function hideItem() 
  238.   if (browserVersion == 1) { 
  239.     if (this.navObj.style.display == "none") 
  240.       return 
  241.     this.navObj.style.display = "none" 
  242.   } else { 
  243.     if (this.navObj.visibility == "hiden") 
  244.       return 
  245.     this.navObj.visibility = "hiden" 
  246.   }     
  247.  
  248. function initializeItem(level, lastNode, leftSide) 
  249. {  
  250.   this.createIndex() 
  251.  
  252.   if (level>0) 
  253.     if (lastNode) //the last 'brother' in the children array 
  254.     { 
  255.       this.renderOb(leftSide + "<img src='_TreeView/ftv2lastnode.gif' width=16 height=22>") 
  256.       leftSide = leftSide + "<img src='_TreeView/ftv2blank.gif' width=16 height=22>"  
  257.     } 
  258.     else 
  259.     { 
  260.       this.renderOb(leftSide + "<img src='_TreeView/ftv2node.gif' width=16 height=22>") 
  261.       leftSide = leftSide + "<img src='_TreeView/ftv2vertline.gif' width=16 height=22>" 
  262.     } 
  263.   else 
  264.     this.renderOb("")   
  265.  
  266. function drawItem(leftSide) 
  267.   if (browserVersion == 2) 
  268.     doc.write("<layer id='item" + this.id + "' top=" + doc.yPos + " visibility=hiden>") 
  269.      
  270.   doc.write("<table ") 
  271.   if (browserVersion == 1) 
  272.     doc.write(" id='item" + this.id + "' style='position:block;' ") 
  273.   doc.write(" border=0 cellspacing=0 cellpadding=0>") 
  274.   doc.write("<tr><td>") 
  275.   doc.write(leftSide) 
  276.   doc.write("<a href='javascript:clickOnFolder("+this.id+")'>") 
  277.   doc.write("<img id='itemIcon"+this.id+"' ") 
  278.   doc.write("src='"+this.iconSrc+"' border=0>") 
  279.   doc.write("</a>") 
  280.   doc.write("</td><td valign=middle nowrap>"+"<a href='javascript:clickOnFolder("+this.id+")'>") 
  281.  // if (USETEXTLINKS)
  282.  //   doc.write("<a href=" + this.link + " target=\"main\">" + this.desc + "</a>")
  283. //  else 
  284.     doc.write(this.desc) 
  285.   doc.write("</a>"+"</table>") 
  286.    
  287.   if (browserVersion == 2) 
  288.     doc.write("</layer>") 
  289.  
  290.   if (browserVersion == 1) { 
  291.     this.navObj = doc.all["item"+this.id] 
  292.     this.iconImg = doc.all["itemIcon"+this.id] 
  293.   } else if (browserVersion == 2) { 
  294.     this.navObj = doc.layers["item"+this.id] 
  295.     this.iconImg = this.navObj.document.images["itemIcon"+this.id] 
  296.     doc.yPos=doc.yPos+this.navObj.clip.height 
  297.   } 
  298.  
  299.  
  300. // Methods common to both objects (pseudo-inheritance) 
  301. // ******************************************************** 
  302.  
  303. function display() 
  304.   if (browserVersion == 1) 
  305.     this.navObj.style.display = "block" 
  306.   else 
  307.     this.navObj.visibility = "show" 
  308.  
  309. function createEntryIndex() 
  310.   this.id = nEntries 
  311.   indexOfEntries[nEntries] = this 
  312.   nEntries++ 
  313.  
  314. // total height of subEntries open 
  315. function totalHeight() //used with browserVersion == 2 
  316.   var h = this.navObj.clip.height 
  317.   var i = 0 
  318.    
  319.   if (this.isOpen) //is a folder and _is_ open 
  320.     for (i=0 ; i < this.nChildren; i++)  
  321.       h = h + this.children[i].totalHeight() 
  322.  
  323.   return h 
  324.  
  325.  
  326. // Events 
  327. // ********************************************************* 
  328.  
  329. function clickOnFolder(folderId) 
  330.   var clicked = indexOfEntries[folderId] 
  331.  
  332. //  if (!clicked.isOpen) 
  333. //    clickOnNode(folderId) 
  334.  
  335.   return  
  336.  
  337. //  if (clicked.isSelected) 
  338.     return 
  339.  
  340. function clickOnNode(folderId) 
  341.   var clickedFolder = 0 
  342.   var state = 0 
  343.  
  344.   clickedFolder = indexOfEntries[folderId] 
  345.   state = clickedFolder.isOpen 
  346.  
  347.   clickedFolder.setState(!state) //open<->close  
  348.  
  349. function initializeDocument() 
  350.   if (doc.all) 
  351.     browserVersion = 1 //IE4   
  352.   else 
  353.     if (doc.layers) 
  354.       browserVersion = 2 //NS4 
  355.     else 
  356.       browserVersion = 0 //other 
  357.  
  358.   foldersTree.initialize(0, 1, "") 
  359.   foldersTree.display()
  360.   
  361.   if (browserVersion > 0) 
  362.   { 
  363.     doc.write("<layer top="+indexOfEntries[nEntries-1].navObj.top+"> </layer>") 
  364.  
  365.     // close the whole tree 
  366.     clickOnNode(0) 
  367.     // open the root folder 
  368.     clickOnNode(0) 
  369.   } 
  370.  
  371. // Auxiliary Functions for Folder-Treee backward compatibility 
  372. // ********************************************************* 
  373.  
  374. function gFld(description, hreference) 
  375.   folder = new Folder(description, hreference) 
  376.   return folder 
  377.  
  378. function gLnk(target, description, linkData) 
  379.   fullLink = "" 
  380.  
  381.   if (target==0) 
  382.   { 
  383.     fullLink = linkData 
  384.   } 
  385.   else 
  386.   { 
  387.     if (target==1) 
  388.        fullLink = "'http://"+linkData+"' target=_blank" 
  389.     else 
  390.        fullLink = "'http://"+linkData+"' target=\"basefrm\"" 
  391.   } 
  392.  
  393.   linkItem = new Item(description, fullLink)   
  394.   return linkItem 
  395.  
  396. function insFld(parentFolder, childFolder) 
  397.   return parentFolder.addChild(childFolder) 
  398.  
  399. function insDoc(parentFolder, document) 
  400.   parentFolder.addChild(document) 
  401.  
  402. // Global variables 
  403. // **************** 
  404.  
  405. USETEXTLINKS = 1 
  406. indexOfEntries = new Array 
  407. nEntries = 0 
  408. doc = document 
  409. browserVersion = 0 
  410. selectedFolder=0
  411.